package com.study.base;

import java.util.HashSet;
import java.util.Objects;

/**
 * Description:
 * User: 27010
 * DateTime: 2018/2/24 10:40
 */
public class StringTest {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder("aaa");
        builder.append("gggg");


        HashSet<StringTest> set = new HashSet();
        StringTest test = new StringTest(1,"10");
        System.out.println(test.hashCode());

        set.add(test);
        test.setA(2);
        System.out.println(test.hashCode());
         set.add(test);

        test.setB("200");
        System.out.println(test.hashCode());
        set.add(test);
        System.out.println(set.size());


    }

    private int a;
    private String b;

    public StringTest(int a, String b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        StringTest that = (StringTest) o;
        return a == that.a &&
                Objects.equals(b, that.b);
    }

    @Override
    public int hashCode() {

        return Objects.hash(a, b);
    }

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }
}
